package com.springboot.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.demo.config.MybatisPlusInterceptorZ;
import com.springboot.demo.entity.po.SysUser;
import com.springboot.demo.service.SysUserService;
import com.springboot.demo.service.impl.mapper.SysUserMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description：
 * @Date： Created in 2021/12/30
 * @author： jianbin.lei
 * @Auto： <a href="mailto:493168771@qq.com">jianbin.lei</a>
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class SysUserServiceImpl  extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    Logger logger = LogManager.getLogger(SysUserServiceImpl.class.getName());

    @Autowired
    private CacheManager cacheManager;

    /**
     * 获取后台用户信息列表
     * @param userName 用户名
     * @return
     */
    @Override
    public List<SysUser> getUserList(String userName) {
        List<SysUser> list = this.baseMapper.selectUserList(userName);
        logger.info("[getUserList]查询结果："+list.size());
        return list;
    }

    /**
     * 根据用户id获取用户信息
     *
     * @param userId 用户id
     * @return 用户信息
     */
    @Override
    public SysUser getUserDetail(Long userId) {
        return this.baseMapper.selectUserDetail(userId);
    }


    @Override
    public Integer selectCountByUserIdAndName(){
        return this.baseMapper.selectCountByUserIdAndName(2L, "jorson");
    }


    @Override
    public SysUser selectById(Long userId) {
        return this.getById(userId);
    }
}
